package com.jy.adscm.order.controller;


import com.jy.adscm.dealer.bean.Dealer;
import com.jy.adscm.dealer.service.DealerService;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.order.bean.JyProduct;
import com.jy.adscm.order.service.JyProductService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-01-18
 */
@RestController
@RequestMapping("/adscm/order/jyProduct")
public class JyProductController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    JyProductService jyProductService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody JyProduct jyProduct, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = jyProductService.insert(jyProduct);
        return new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody JyProduct jyProduct, HttpServletRequest request) throws AdscmSystemException {
        boolean insert = jyProductService.updateById(jyProduct);
        return new SimpleCoreResponse("200","修改成功",insert);
    }
    @RequestMapping("selectAll")
    public SimpleCoreResponse selectAllt( HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<JyProduct> jyProducts = jyProductService.selectList(null);
        return new SimpleCoreResponse("200","查询成功",jyProducts);
    }
}

